package com.lagou.servlet;

import com.lagou.bena.Student;
import com.lagou.service.AdminServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "stuListServlet", urlPatterns = "/main")
public class stuListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建AdminServiceImp类型的对象对前端输入的数据进行校验
        AdminServiceImp asi = new AdminServiceImp();
        List<Student> students = asi.showAllService();
        // 将查询出的所有学生信息集合存入session对象中实现多个请求共享
        request.getSession().setAttribute("students", students);
        // 实现客户端的跳转
        response.sendRedirect("stuList.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
